/**
 * 35.搜索插入位置
 */
public class AddPosition {

    public static int findPosition(int[] n,int tar) {
        int left = 0;
        int right = n.length - 1;
        while (left <= right) {
            int mid = (right - left) / 2 + left;
            int m = n[mid];
            if (m < tar) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return left;
    }

    public static void main(String[] args) {
        int[] n={1,3,5,6};
        System.out.println(findPosition(n,5));
    }
}
